package string.compare;

/**
 * @Classname : CountBinarySubstrings
 * @Description : 696. 计数二进制子串
 * https://leetcode.cn/problems/count-binary-substrings/
 * @Author : chentianyu
 * @Date 2022/12/10 21:13
 */


public class CountBinarySubstrings {
    public int countBinarySubstrings(String s) {
        // pre：上一个数字的个数；cur：当前数字的个数；last：上一个数字的值；count：目标二进制子串的个数
        int pre = 0, cur = 0, last = '#', count = 0;
        for (char c : s.toCharArray()) {
            if (c != last) {
                pre = cur;
                cur = 0;
            }
            cur++;
            if (pre >= cur) count++;
            last = c;
        }
        return count;
    }
}
